<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel app\models\ArcClassifySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '质检机器人分类种类';
$this->params['breadcrumbs'][] = ['label' => '分类种类', 'url' => ['index']];
?>
<div class="arc-classify-index">

    <h4>点击按钮添加质检机器人分类种类</h4>
    <?= $this->render('/common/dialog')?>
    <p>
        <?= Html::a('新增', ['create'], ['class' => 'btn btn-info fa fa-plus']) ?>
    </p>

    <?= GridView::widget([
    	'id' => 'grid',
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
		'pager'=>[
				//'options'=>['class'=>'hidden']//关闭自带分页
			'firstPageLabel'=>"第一页",
			'lastPageLabel'=>'最后一页',
		],
    	'showFooter' => true,  //设置显示最下面的footer
        'columns' => [
            ['class' => 'yii\grid\SerialColumn',
                'options'=>[
                    'width'=>'5%',
                ]
            ],
            [
            	'attribute' =>'name',
                'filter' => '<input type="text" class="form-control" name="ArcClassifySearchModel[name]"  placeholder="输入名称查询">',
                'footer' => '<input id="num"  type="number" href="#" class="btn btn-default btn-xs btn-delete" placeholder="每页显示的条数"/>',
            	'value'=>
            		function($model){
            			if(mb_strlen($model->name)>10){
            				return  mb_substr($model->name, 0,10).'...';   //主要通过此种方式实现
            			}else{
            				return $model->name;
            			}
            		},
            		'options'=>[
            				'width'=>'30%',
            		]
        	],
        	[
        		'attribute' =>'content',
                'filter' => '<input type="text" class="form-control" name="ArcClassifySearchModel[content]"  placeholder="输入内容查询">',
                'value'=>
		        	function($model){
		        		if(mb_strlen($model->content)>20){
		        			return  mb_substr($model->content, 0,20).'...';   //主要通过此种方式实现
		        		}else{
		        			return $model->content;
		        		}
		        	},
		        	'options'=>[
		        			'width'=>'40%',
		        	]
        	],
            ['class' => 'yii\grid\ActionColumn',//下面是新增加的按按钮
                'header' => '操作',
                'template' => '{view}&nbsp;&nbsp;{update}&nbsp;&nbsp;{delete}',
                'buttons' => [
                    'view'=> function ($url, $model, $key) {
                        return '<a href="'.$url.'" class="btn btn-success fa fa-sticky-note-o">详情</a>';
                    },
                    'update'=> function ($url, $model, $key) {
                        return '<a href="'.$url.'" class="btn btn-info fa fa-edit">修改</a>';
                    },
                    'delete'=> function ($url, $model, $key) {
                        return '<a href="'.$url.'" title="删除" aria-label="删除" data-pjax="0" data-confirm="您确定要删除此项吗？删除此项会删除相应的电话号码记录。" data-method="post"><span class="btn btn-danger fa fa-remove">删除</span></a>';
                    },
                ],
                'options' => [
                    'width' => '13%',
                ],
            ],
        ],
    ]); ?>
</div>

<script type="text/javascript">
$(function(){ 

	$("#deleteMany").click(function(){
        var deleteIds = $("#grid").yiiGridView("getSelectedRows");
        if(deleteIds == null || deleteIds == ""){
        	krajeeDialog.alert("请选择要删除的记录！");
        	return false;
        }
    	krajeeDialog.confirm("确认是否要删除这些记录？",function(result){
			if(result){
                var url = "delete-ids";
                $.ajax({
                	type:"post",
                	async:true,
                	cache:false,
                	url:url,/*url写异域的请求地址*/
                	data:{
                    	ids:deleteIds
                	},
                	success: function(datas){
                		krajeeDialog.alert("刪除成功！");
                		location.reload();
                	},
                	error: function(error){
                		krajeeDialog.alert('删除数据失败，请联系超级管理员！');
                	}
                });
			}
        });
    });

	$("#num").blur(function(){//当鼠标失去焦点时就出发事件，实现分页的页改变
        var url = "<?= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ?>";
        $.ajax({
        	type:"post",
        	async:true,
        	cache:false,
        	url:url,/*url写异域的请求地址*/
        	data:{
            	pageSize:$("#num").val()
        	},
        	success: function(datas){
        		window.location.reload()
        	},
        	error: function(error){
        	}
        });
    });

});
</script>